import { ContactApi } from '~/api/ContactApi'
import { ContactModel } from './ContactModel'

export async function contactFromId(id: number): Promise<ContactModel> {
  const contacts = await ContactApi.getAll()
  const contact = contacts.find(x => x.id === id)
  if (!contact) {
    throw new Error(`contactFromId(id: ${id}): no such contact`)
  }
  return contact
}